var n;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var BundleConfig = require("AA_BundleConfig");
var LogManager = require("AA_LogManager");
var SingletonManager = require("AA_SingletonManager");
var u = function (e) {
  function t() {
    return null !== e && e.apply(this, arguments) || this;
  }
  __extends(t, e);
  t.prototype.loadBundle = function (e) {
    return new Promise(function (t) {
      var o = cc.assetManager.getBundle(e);
      e == BundleConfig.BundleNames.Resoucess && (o = cc.resources);
      if (o) {
        t(o);
      } else {
        cc.assetManager.loadBundle(e, function (o, n) {
          if (o) {
            LogManager.LogMgr.error("Failed to load bundle: " + e);
            t(null);
          } else {
            t(n);
          }
        });
      }
    });
  };
  t.prototype.loadRes = function (e, t, o) {
    var n = this;
    return new Promise(function (i) {
      return __awaiter(n, undefined, undefined, function () {
        return __generator(this, function (n) {
          switch (n.label) {
            case 0:
              if ("string" != typeof e) {
                return [3, 2];
              } else {
                return [4, this.loadBundle(e)];
              }
            case 1:
              e = n.sent();
              n.label = 2;
            case 2:
              e.load(t, o, function (o, n) {
                if (o) {
                  LogManager.LogMgr.error("Failed to load res: bundle:" + e + " , url:" + t);
                  i(null);
                } else {
                  i(n);
                }
              });
              return [2];
          }
        });
      });
    });
  };
  t.prototype.loadDir = function (e, t, o) {
    var n = this;
    return new Promise(function (i) {
      return __awaiter(n, undefined, undefined, function () {
        return __generator(this, function (n) {
          switch (n.label) {
            case 0:
              if ("string" != typeof e) {
                return [3, 2];
              } else {
                return [4, this.loadBundle(e)];
              }
            case 1:
              e = n.sent();
              n.label = 2;
            case 2:
              e.loadDir(t, o, function (o, n) {
                if (o) {
                  LogManager.LogMgr.error("Failed to load dir: " + e + " , " + t);
                  i(null);
                } else {
                  i(n);
                }
              });
              return [2];
          }
        });
      });
    });
  };
  t.prototype.loadRemote = function (e, t) {
    t = t || {};
    return new Promise(function (o) {
      if (e) {
        cc.assetManager.loadRemote(e, t, function (e, t) {
          o(e ? null : t);
        });
      } else {
        o(null);
      }
    });
  };
  return t;
}(SingletonManager.SingletonMgr);
exports.default = u.getInstance();